<template>
  <div>
    <div>
      <el-button
        type="primary"
        icon="el-icon-plus
"
        @click="order"
        >场地预约</el-button
      >
    </div>
    <div>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="orderName" label="预约名称"> </el-table-column>
        <el-table-column prop="orderNominal" label="预定名义">
        </el-table-column>
        <el-table-column prop="orderTitle" label="活动标题"> </el-table-column>
        <el-table-column prop="orderDetail" label="详细描述"> </el-table-column>
        <el-table-column prop="personNumber" label="参与人数">
        </el-table-column>
        <el-table-column prop="user.userName" label="联系人"> </el-table-column>
        <el-table-column prop="orderTel" label="联系电话"> </el-table-column>
        <el-table-column prop="orderWay" label="结算方式"> </el-table-column>
        <el-table-column prop="orderStart" label="预定开始时间">
        </el-table-column>
        <el-table-column prop="orderEnd" label="预定结束时间">
        </el-table-column>
        <el-table-column prop="site.sitePlace" label="球场地址">
        </el-table-column>
        <el-table-column prop="site.siteName" label="球场名称">
        </el-table-column>
        <el-table-column prop="site.sitePersonNumber" label="球场容积(人)">
        </el-table-column>
        <el-table-column prop="site.sitePrice" label="租赁价格">
        </el-table-column>
        <el-table-column prop="site.siteDiscount" label="租赁折扣">
        </el-table-column>
      </el-table>
    </div>
    <div>
      <el-dialog title="场地预约" :visible.sync="dialogFormVisible">
        {{ insertData }}
        <el-form :model="insertData">
          <el-form-item label="预约名称" :label-width="formLabelWidth">
            <el-input
              v-model="insertData.orderName"
              autocomplete="off"
              style="width: 300px"
            ></el-input>
          </el-form-item>
          <el-form-item label="预约名义" :label-width="formLabelWidth">
            <el-radio v-model="insertData.orderNominal" label="个人"
              >个人</el-radio
            >
            <el-radio v-model="insertData.orderNominal" label="公司"
              >公司</el-radio
            >
          </el-form-item>
          <el-form-item label="参与人数" :label-width="formLabelWidth">
            <el-input-number
              v-model="insertData.personNumber"
              :min="1"
              label="描述文字"
              @change="myChange()"
            ></el-input-number>
          </el-form-item>
          <el-form-item label="选择场地" :label-width="formLabelWidth">
            <el-select
              v-model="insertData.orderType"
              placeholder="请选择"
              @change="myChangeType"
            >
              <el-option
                v-for="item in siteList"
                :key="item.id"
                :label="item.siteName"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="活动标题" :label-width="formLabelWidth">
            <el-input
              v-model="insertData.orderTitle"
              autocomplete="off"
              style="width: 300px"
            ></el-input>
          </el-form-item>

          <el-form-item label="详细描述" :label-width="formLabelWidth">
            <vue-editor v-model="insertData.orderDetail"></vue-editor>
          </el-form-item>
          <el-form-item label="联系电话" :label-width="formLabelWidth">
            <el-input
              v-model="insertData.orderTel"
              autocomplete="off"
              style="width: 300px"
            ></el-input>
          </el-form-item>
          <el-form-item label="结算方式" :label-width="formLabelWidth">
            <el-radio v-model="insertData.orderWay" label="微信">微信</el-radio>
            <el-radio v-model="insertData.orderWay" label="支付宝"
              >支付宝</el-radio
            >
            <el-radio v-model="insertData.orderWay" label="现金支付"
              >现金支付</el-radio
            >
          </el-form-item>
          <el-form-item label="日期选择" :label-width="formLabelWidth">
            <el-date-picker
              v-model="insertData.orderStart"
              type="datetime"
              placeholder="选择开始日期"
              value-format="yyyy-MM-dd HH:mm:ss"
            >
            </el-date-picker
            >---<el-date-picker
              v-model="insertData.orderEnd"
              type="datetime"
              placeholder="选择结束日期"
              value-format="yyyy-MM-dd HH:mm:ss"
            >
            </el-date-picker>
          </el-form-item>
          <h4>价格：</h4>
          {{ moneyData.sitePrice }}&emsp;
          <h4>折扣：</h4>
          {{ moneyData.siteDiscount }}&emsp;
          <h4>合计：</h4>
          {{ moneyData.siteDiscount + moneyData.sitePrice }}
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="sureInsert">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import {
  orderList,
  getSiteListByPersonNumber,
  getOrderById,
  insertOrder,
} from "@/api/orderApi";
export default {
  data() {
    return {
      moneyData: [],
      siteList: [],
      insertData: {
        id: null,
        orderName: null,
        orderNominal: null,
        orderType: null,
        orderTitle: null,
        orderDetail: null,
        personNumber: null,
        orderTel: null,
        orderWay: null,
        orderStart: null,
        orderEnd: null,
      },
      dialogFormVisible: false,
      tableData: [],
    };
  },
  created() {
    this.list();
  },
  methods: {
    myChangeType() {
      getOrderById(this.insertData.orderType).then((res) => {
        this.moneyData = res.data.data;
      });
    },
    sureInsert() {
      insertOrder(this.insertData).then((result) => {
        alert(result.data.data);
        this.dialogFormVisible = false;
      });
    },
    myChange() {
      getSiteListByPersonNumber(this.insertData.personNumber).then((result) => {
        this.siteList = result.data.data;
      });
    },
    order() {
      this.insertData.personNumber = 1;
      this.myChange();
      this.dialogFormVisible = true;
    },
    list() {
      orderList().then((res) => {
        this.tableData = res.data.data;
      });
    },
  },
};
</script>
